package com.amtf.datafile3.core.std;

import com.amtf.datafile3.DataRecordParser;
import com.amtf.datafile3.DataRecordRender;
import com.amtf.datafile3.DataTable;
import com.amtf.datafile3.DataTableDefinition;

public abstract class AbsDataTable<RECORD_TYPE, FIELD_TYPE> implements DataTable {

	protected String name = "";
	protected int currentReadingLine = 0;
	protected int currentWritenLine = 0;
	protected DataTableDefinition definition = null;
	protected DataRecordParser<RECORD_TYPE, FIELD_TYPE> recordParser;
	protected DataRecordRender recordRender;

	public AbsDataTable(String name, DataTableDefinition definition) {
		this.name = name;
		this.definition = definition;
		this.recordParser = definition.getParser();
		this.recordRender = definition.getRender();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public DataTableDefinition getDefinition() {
		return definition;
	}

	public void setDefinition(DataTableDefinition definition) {
		this.definition = definition;
		this.recordParser = definition.getParser();
		this.recordRender = definition.getRender();
	}

	public int currentReadingLine() {
		return currentReadingLine;
	}

	public int currentWritenLine() {
		return currentWritenLine;
	}

	public void resetColumnLike(DataTableDefinition definition) {
		recordParser.resetColumnLike(definition, this.definition);
	}
}
